package day11demo;

import java.util.Random;
//验证码
public class Demo4 {
    public static void main(String[] args) {
        String str = VerificationCode();
        System.out.println(str);

    }

    public static String VerificationCode() {
        char[] arr = new char[5];
        Random r = new Random();
        char[] word = new char[62];
        int a = 97, A = 65, zero = 48;
        for (int i = 0; i < word.length; i++) {
            if (i < 26) {
                word[i] = (char) a;
                a++;
            } else if (i >= 26 && i < 52) {
                word[i] = (char) A;
                A++;
            } else {
                word[i] = (char) zero;
                zero++;
            }
        }
        for (int i = 0; i < arr.length; i++) {
            if (i == arr.length -1) {
                int number = r.nextInt(11) + 52;
                arr[i] = word[number];
            } else {
                int randomNumber = r.nextInt(52);
                arr[i] = word[randomNumber];
            }
        }

        for (int i = 0; i < arr.length; i++) {
            int arrNumber = r.nextInt(5);
            char cha = arr[i];
            arr[i] = arr[arrNumber];
            arr[arrNumber] = cha;
        }
        String result = new String(arr);
        return result;

    }
}
